﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient;
using System.Data;

namespace OPMS_V1.DOL
{
    public class UserDOL
    {
        //This is the connection string for the database located at the localhost
        private const String connString = "server=localhost;database=OPMS;Integrated Security=SSPI";

        //Creating the SQLConnection using Connection String
        SqlConnection conn = new SqlConnection(connString);
        SqlDataReader reader = null;

        /// <summary>
        /// This function is used for Getting the Public User Details
        /// </summary>
        /// <param name="accountname"></param>
        /// <returns></returns>
        public DataSet Get_UserDetails(string accountname)
        {
            DataSet data = new DataSet();
            using (SqlCommand command = new SqlCommand("Get_User_Details", conn))
            {
                try
                {
                    //Open the SQL Connection
                    conn.Open();

                    //Run the command type as a stored procedure
                    command.CommandType = CommandType.StoredProcedure;
                    command.Parameters.Add("@loginID", SqlDbType.VarChar, 50).Value = accountname;
                    //Execute the reader for retrieving the results from the database
                    //reader = command.ExecuteReader();

                    //If results forund the read the data
                    SqlDataAdapter da = new SqlDataAdapter(command);
                    //Filling the DataSet with the List of Area Information

                    da.Fill(data);
                }
                catch (SqlException)
                { return null; }
                finally
                {
                    //If the connection state is open then close the connection to the database.
                    if (conn.State == ConnectionState.Open)
                    {//Close the connection
                        conn.Close();
                    }
                }
            }
            return data;
        }
    }
}
